package com.migu.config;

/**
 * @Description TODO :
 * @Author: zj
 * @Date: 16:55 2019/3/22
 * @Version 1.0
 **/

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;
import java.util.List;

@Configuration
@EnableSwagger2
public class Swagger2 {

    @Bean
    public Docket createRestApi() {
        ParameterBuilder tickePar = new ParameterBuilder();
        List<Parameter> parameterList = new ArrayList<>();
        tickePar.name("Authorization").description("user Authorization")
                .modelRef(new ModelRef("String")).parameterType("header")
                .required(false).build();
        parameterList.add(tickePar.build());

        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.migu.rbac.controller"))//扫描包
                //.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)) //被注解的方法
                .paths(PathSelectors.any())
                .build()
                .globalOperationParameters(parameterList);
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("Api")
                .description("---一个说明-----")
                .termsOfServiceUrl("http://blog.didispace.com/")
                .contact("程序猿")
                .version("1.0")
                .build();
    }
}
